<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.11.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>cppMISC: include/designM/singleton.hpp 源文件</title>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="../../clipboard.js"></script>
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../resize.js"></script>
<script type="text/javascript" src="../../cookie.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/javascript" src="../../darkmode_toggle.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">cppMISC<span id="projectnumber">&#160;v1.1</span>
   </div>
   <div id="projectbrief">cppMisc 文档系统</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.11.0 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "../../search/",'.html');
/* @license-end */
</script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() { codefold.init(1); });
/* @license-end */
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('../../',true,false,'search.php','搜索',false);
  $(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function(){ initResizable(false); });
/* @license-end */
</script>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">载入中...</div>
<div class="SRStatus" id="Searching">搜索中...</div>
<div class="SRStatus" id="NoMatches">未找到</div>
</div>
</div>
</div>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="../../dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="../../dir_7815f4a69fa470e020068bb120d080ef.html">designM</a></li>  </ul>
</div>
</div><!-- top -->
<div id="doc-content">
<div class="header">
  <div class="headertitle"><div class="title">singleton.hpp</div></div>
</div><!--header-->
<div class="contents">
<a href="../../de/d6d/singleton_8hpp.html">浏览该文件的文档.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno">    1</span> </div>
<div class="line"><a id="l00009" name="l00009"></a><span class="lineno">    9</span><span class="preprocessor">#pragma once</span></div>
<div class="line"><a id="l00010" name="l00010"></a><span class="lineno">   10</span> </div>
<div class="line"><a id="l00011" name="l00011"></a><span class="lineno">   11</span><span class="preprocessor">#include &lt;memory&gt;</span></div>
<div class="line"><a id="l00012" name="l00012"></a><span class="lineno">   12</span><span class="preprocessor">#include &lt;type_traits&gt;</span></div>
<div class="line"><a id="l00013" name="l00013"></a><span class="lineno">   13</span> </div>
<div class="line"><a id="l00014" name="l00014"></a><span class="lineno">   14</span><span class="keyword">namespace </span><a class="code hl_namespace" href="../../df/d8d/namespacewheels.html">wheels</a></div>
<div class="line"><a id="l00015" name="l00015"></a><span class="lineno">   15</span>{</div>
<div class="line"><a id="l00016" name="l00016"></a><span class="lineno">   16</span>    <span class="keyword">namespace </span>dm</div>
<div class="line"><a id="l00017" name="l00017"></a><span class="lineno">   17</span>    {</div>
<div class="line"><a id="l00018" name="l00018"></a><span class="lineno">   18</span>        <span class="keyword">template</span>&lt; <span class="keyword">typename</span> typeName &gt;</div>
<div class="foldopen" id="foldopen00019" data-start="{" data-end="};">
<div class="line"><a id="l00019" name="l00019"></a><span class="lineno"><a class="line" href="../../de/d44/classwheels_1_1dm_1_1singleton.html">   19</a></span>        <span class="keyword">class </span><a class="code hl_class" href="../../de/d44/classwheels_1_1dm_1_1singleton.html">singleton</a></div>
<div class="line"><a id="l00020" name="l00020"></a><span class="lineno">   20</span>        {</div>
<div class="line"><a id="l00021" name="l00021"></a><span class="lineno">   21</span>        <span class="keyword">public</span>:</div>
<div class="line"><a id="l00022" name="l00022"></a><span class="lineno"><a class="line" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#a49cbde8528bcf4e2daa32e6b09e9039c">   22</a></span>            <span class="keyword">using </span><a class="code hl_typedef" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#a49cbde8528bcf4e2daa32e6b09e9039c">T</a> = <span class="keyword">typename</span> std::enable_if&lt; std::is_class&lt; typeName &gt;::value , typeName &gt;::type;</div>
<div class="line"><a id="l00023" name="l00023"></a><span class="lineno">   23</span>        <span class="keyword">protected</span>:</div>
<div class="line"><a id="l00024" name="l00024"></a><span class="lineno"><a class="line" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#a068f4f3064ec965938e0d99d2b890be7">   24</a></span>            <span class="keyword">static</span> std::shared_ptr&lt; T &gt; <a class="code hl_variable" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#a068f4f3064ec965938e0d99d2b890be7">pt_obj__</a>;</div>
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno">   25</span>        <span class="keyword">protected</span>:</div>
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno"><a class="line" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#a486422f98733581c4462792f61c41fcf">   27</a></span>            <a class="code hl_function" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#a486422f98733581c4462792f61c41fcf">singleton</a>(){}</div>
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno">   28</span>        <span class="keyword">public</span>:</div>
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno"><a class="line" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#ae71c401e1f6a3fdd97ed39b821025952">   29</a></span>            <a class="code hl_function" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#ae71c401e1f6a3fdd97ed39b821025952">singleton</a>( <span class="keyword">const</span> <a class="code hl_class" href="../../de/d44/classwheels_1_1dm_1_1singleton.html">singleton</a>&amp; ) = <span class="keyword">delete</span>;</div>
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno"><a class="line" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#a00d55bdcea0b0896937c58ab2b9cb9a3">   30</a></span>            <a class="code hl_function" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#a00d55bdcea0b0896937c58ab2b9cb9a3">singleton</a>( <a class="code hl_class" href="../../de/d44/classwheels_1_1dm_1_1singleton.html">singleton</a>&amp;&amp; ) = <span class="keyword">delete</span>;</div>
<div class="line"><a id="l00035" name="l00035"></a><span class="lineno">   35</span>            <span class="keyword">template</span>&lt; <span class="keyword">typename</span> ...Args &gt;</div>
<div class="foldopen" id="foldopen00036" data-start="{" data-end="}">
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno"><a class="line" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#ab0f35771c8d539c732b6a4e40bcedeaf">   36</a></span>            <span class="keyword">static</span> <a class="code hl_typedef" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#a49cbde8528bcf4e2daa32e6b09e9039c">T</a> * <a class="code hl_function" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#ab0f35771c8d539c732b6a4e40bcedeaf">create</a>( Args&amp;&amp;... args ){</div>
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno">   37</span>                <span class="keywordflow">if</span>( <a class="code hl_variable" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#a068f4f3064ec965938e0d99d2b890be7">pt_obj__</a> ) <span class="keywordflow">return</span> <a class="code hl_variable" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#a068f4f3064ec965938e0d99d2b890be7">pt_obj__</a>.get();</div>
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno">   38</span> </div>
<div class="line"><a id="l00039" name="l00039"></a><span class="lineno">   39</span> </div>
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno">   40</span>                <a class="code hl_variable" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#a068f4f3064ec965938e0d99d2b890be7">pt_obj__</a> = std::make_shared&lt; T &gt;( std::forward&lt; Args &gt;(args)...);</div>
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno">   41</span>                </div>
<div class="line"><a id="l00042" name="l00042"></a><span class="lineno">   42</span>                <a class="code hl_typedef" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#a49cbde8528bcf4e2daa32e6b09e9039c">T</a> * ret = <a class="code hl_variable" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#a068f4f3064ec965938e0d99d2b890be7">pt_obj__</a>.get();</div>
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno">   43</span>                <span class="keywordflow">return</span> ret;</div>
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno">   44</span>            }</div>
</div>
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno">   45</span> </div>
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno">   46</span>            <span class="keyword">template</span>&lt; <span class="keyword">typename</span> ...Args &gt;</div>
<div class="foldopen" id="foldopen00047" data-start="{" data-end="}">
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno"><a class="line" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#aff26d3af3d193f057a15cb6d25c5062c">   47</a></span>            <span class="keyword">static</span> std::shared_ptr&lt; T &gt; <a class="code hl_function" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#aff26d3af3d193f057a15cb6d25c5062c">create_shared</a>( Args&amp;&amp;... args ){</div>
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno">   48</span>                <span class="keywordflow">if</span>( <a class="code hl_variable" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#a068f4f3064ec965938e0d99d2b890be7">pt_obj__</a> ) <span class="keywordflow">return</span> <a class="code hl_variable" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#a068f4f3064ec965938e0d99d2b890be7">pt_obj__</a>;</div>
<div class="line"><a id="l00049" name="l00049"></a><span class="lineno">   49</span> </div>
<div class="line"><a id="l00050" name="l00050"></a><span class="lineno">   50</span>                <a class="code hl_variable" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#a068f4f3064ec965938e0d99d2b890be7">pt_obj__</a>= std::make_shared&lt; T &gt;( std::forward&lt; Args &gt;(args)...);</div>
<div class="line"><a id="l00051" name="l00051"></a><span class="lineno">   51</span> </div>
<div class="line"><a id="l00052" name="l00052"></a><span class="lineno">   52</span>                <span class="keywordflow">return</span> <a class="code hl_variable" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#a068f4f3064ec965938e0d99d2b890be7">pt_obj__</a>;</div>
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno">   53</span>            }</div>
</div>
<div class="line"><a id="l00054" name="l00054"></a><span class="lineno">   54</span> </div>
<div class="foldopen" id="foldopen00059" data-start="{" data-end="}">
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno"><a class="line" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#ab064e1d47abf923e4ae0deaac875c173">   59</a></span>            <span class="keyword">static</span> <a class="code hl_typedef" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#a49cbde8528bcf4e2daa32e6b09e9039c">T</a> * <a class="code hl_function" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#ab064e1d47abf923e4ae0deaac875c173">get</a>(){</div>
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno">   60</span>                <span class="keywordflow">return</span> <a class="code hl_variable" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#a068f4f3064ec965938e0d99d2b890be7">pt_obj__</a>.get();</div>
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno">   61</span>            }</div>
</div>
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno">   62</span> </div>
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno"><a class="line" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#a4c95860231735ce03395968f726d0246">   63</a></span>            <span class="keyword">static</span> std::shared_ptr&lt; T &gt; <a class="code hl_function" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#a4c95860231735ce03395968f726d0246">get_shared</a>(){ <span class="keywordflow">return</span> <a class="code hl_variable" href="../../de/d44/classwheels_1_1dm_1_1singleton.html#a068f4f3064ec965938e0d99d2b890be7">pt_obj__</a>; }</div>
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno">   64</span> </div>
<div class="line"><a id="l00065" name="l00065"></a><span class="lineno">   65</span>        };</div>
</div>
<div class="line"><a id="l00066" name="l00066"></a><span class="lineno">   66</span> </div>
<div class="line"><a id="l00067" name="l00067"></a><span class="lineno"><a class="line" href="../../de/d6d/singleton_8hpp.html#a1109a2b8f185c4c408a6772a1911488f">   67</a></span><span class="preprocessor">#define IMP_SINGLETON( type )   template&lt;&gt; std::shared_ptr&lt; type &gt; singleton&lt; type &gt; :: pt_obj__ = {}</span></div>
<div class="line"><a id="l00068" name="l00068"></a><span class="lineno">   68</span>    }</div>
<div class="line"><a id="l00069" name="l00069"></a><span class="lineno">   69</span>}</div>
<div class="line"><a id="l00070" name="l00070"></a><span class="lineno">   70</span> </div>
<div class="ttc" id="aclasswheels_1_1dm_1_1singleton_html"><div class="ttname"><a href="../../de/d44/classwheels_1_1dm_1_1singleton.html">wheels::dm::singleton</a></div><div class="ttdef"><b>定义</b> <a href="#l00019">singleton.hpp:20</a></div></div>
<div class="ttc" id="aclasswheels_1_1dm_1_1singleton_html_a00d55bdcea0b0896937c58ab2b9cb9a3"><div class="ttname"><a href="../../de/d44/classwheels_1_1dm_1_1singleton.html#a00d55bdcea0b0896937c58ab2b9cb9a3">wheels::dm::singleton::singleton</a></div><div class="ttdeci">singleton(singleton &amp;&amp;)=delete</div></div>
<div class="ttc" id="aclasswheels_1_1dm_1_1singleton_html_a068f4f3064ec965938e0d99d2b890be7"><div class="ttname"><a href="../../de/d44/classwheels_1_1dm_1_1singleton.html#a068f4f3064ec965938e0d99d2b890be7">wheels::dm::singleton::pt_obj__</a></div><div class="ttdeci">static std::shared_ptr&lt; T &gt; pt_obj__</div><div class="ttdef"><b>定义</b> <a href="#l00024">singleton.hpp:24</a></div></div>
<div class="ttc" id="aclasswheels_1_1dm_1_1singleton_html_a486422f98733581c4462792f61c41fcf"><div class="ttname"><a href="../../de/d44/classwheels_1_1dm_1_1singleton.html#a486422f98733581c4462792f61c41fcf">wheels::dm::singleton::singleton</a></div><div class="ttdeci">singleton()</div><div class="ttdoc">避免直接调用构造函数</div><div class="ttdef"><b>定义</b> <a href="#l00027">singleton.hpp:27</a></div></div>
<div class="ttc" id="aclasswheels_1_1dm_1_1singleton_html_a49cbde8528bcf4e2daa32e6b09e9039c"><div class="ttname"><a href="../../de/d44/classwheels_1_1dm_1_1singleton.html#a49cbde8528bcf4e2daa32e6b09e9039c">wheels::dm::singleton::T</a></div><div class="ttdeci">typename std::enable_if&lt; std::is_class&lt; typeName &gt;::value, typeName &gt;::type T</div><div class="ttdef"><b>定义</b> <a href="#l00022">singleton.hpp:22</a></div></div>
<div class="ttc" id="aclasswheels_1_1dm_1_1singleton_html_a4c95860231735ce03395968f726d0246"><div class="ttname"><a href="../../de/d44/classwheels_1_1dm_1_1singleton.html#a4c95860231735ce03395968f726d0246">wheels::dm::singleton::get_shared</a></div><div class="ttdeci">static std::shared_ptr&lt; T &gt; get_shared()</div><div class="ttdef"><b>定义</b> <a href="#l00063">singleton.hpp:63</a></div></div>
<div class="ttc" id="aclasswheels_1_1dm_1_1singleton_html_ab064e1d47abf923e4ae0deaac875c173"><div class="ttname"><a href="../../de/d44/classwheels_1_1dm_1_1singleton.html#ab064e1d47abf923e4ae0deaac875c173">wheels::dm::singleton::get</a></div><div class="ttdeci">static T * get()</div><div class="ttdoc">获取当前的模块对象指针</div><div class="ttdef"><b>定义</b> <a href="#l00059">singleton.hpp:59</a></div></div>
<div class="ttc" id="aclasswheels_1_1dm_1_1singleton_html_ab0f35771c8d539c732b6a4e40bcedeaf"><div class="ttname"><a href="../../de/d44/classwheels_1_1dm_1_1singleton.html#ab0f35771c8d539c732b6a4e40bcedeaf">wheels::dm::singleton::create</a></div><div class="ttdeci">static T * create(Args &amp;&amp;... args)</div><div class="ttdoc">工厂函数，用来创建单例对象</div><div class="ttdef"><b>定义</b> <a href="#l00036">singleton.hpp:36</a></div></div>
<div class="ttc" id="aclasswheels_1_1dm_1_1singleton_html_ae71c401e1f6a3fdd97ed39b821025952"><div class="ttname"><a href="../../de/d44/classwheels_1_1dm_1_1singleton.html#ae71c401e1f6a3fdd97ed39b821025952">wheels::dm::singleton::singleton</a></div><div class="ttdeci">singleton(const singleton &amp;)=delete</div></div>
<div class="ttc" id="aclasswheels_1_1dm_1_1singleton_html_aff26d3af3d193f057a15cb6d25c5062c"><div class="ttname"><a href="../../de/d44/classwheels_1_1dm_1_1singleton.html#aff26d3af3d193f057a15cb6d25c5062c">wheels::dm::singleton::create_shared</a></div><div class="ttdeci">static std::shared_ptr&lt; T &gt; create_shared(Args &amp;&amp;... args)</div><div class="ttdef"><b>定义</b> <a href="#l00047">singleton.hpp:47</a></div></div>
<div class="ttc" id="anamespacewheels_html"><div class="ttname"><a href="../../df/d8d/namespacewheels.html">wheels</a></div><div class="ttdoc">堆栈信息读取和保存记录</div><div class="ttdef"><b>定义</b> <a href="../../d3/df7/ary__str_8hpp_source.html#l00006">ary_str.hpp:7</a></div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
制作者&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.11.0
</small></address>
</div><!-- doc-content -->
</body>
</html>
